﻿using System.ComponentModel;

namespace QInfrastructure.Models;

#nullable disable

public class QPermissionKey
{

    /// <summary>
    /// 查询
    /// </summary>
    [Description("查询")]
    public const long Query = 1;
    /// <summary>
    /// 新增
    /// </summary>
    [Description("新增")]
    public const long Add = 2;
    /// <summary>
    /// 修改
    /// </summary>
    [Description("修改")]
    public const long Update = 4;
    /// <summary>
    /// 删除
    /// </summary>
    [Description("删除")]
    public const long Delete = 8;



    #region 对权限码的基本操作

    private static List<(string CName, string EName, long CodeVal)> PermissionKeysCache = new List<(string CName, string EName, long CodeVal)>();
    public static List<(string CName,string EName,long CodeVal)> GetQPermissionKeys()
    {
        if(PermissionKeysCache.Count>0) return PermissionKeysCache;
        var res = new List<(string CName, string EName, long CodeVal)>();
		var fileds = typeof(QPermissionKey).GetFields();
		foreach (var f in fileds)
		{
			var descAttr = f.GetCustomAttributes(typeof(DescriptionAttribute), true).FirstOrDefault() as DescriptionAttribute;
			if (f.CustomAttributes.Count() <= 0 || descAttr == null) continue;

			var cName = descAttr.Description;
			var eName = f.Name;
			var codeVal = (long)f.GetRawConstantValue();
			res.Add((cName, eName, codeVal));

		}
        PermissionKeysCache = res;
		return res;
	}
	#endregion


}